<?php

App::uses('AppController', 'Controller');

/**
 * TBPERFILs Controller
 *
 * @property TBPERFIL $TBPERFIL
 */
class PerfisController extends AppController {

    /**
     * Helpers
     *
     * @var array
     */
    public $helpers = array('Js');

    /**
     * index method
     *
     * @return void
     */
    public function index() {
        $this->TBPERFIL->recursive = 0;
        $this->set('tBPERFILs', $this->paginate());
    }

    /**
     * view method
     *
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function view($id = null) {
        if (!$this->TBPERFIL->exists($id)) {
            throw new NotFoundException(__('Invalid t b p e r f i l'));
        }
        $options = array('conditions' => array('TBPERFIL.' . $this->TBPERFIL->primaryKey => $id));
        $this->set('tBPERFIL', $this->TBPERFIL->find('first', $options));
    }

    /**
     * add method
     *
     * @return void
     */
    public function add() {
        if ($this->request->is('post')) {
            $this->TBPERFIL->create();
            if ($this->TBPERFIL->save($this->request->data)) {
                $this->Session->setFlash(__('The t b p e r f i l has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The t b p e r f i l could not be saved. Please, try again.'));
            }
        }
    }

    /**
     * edit method
     *
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function edit($id = null) {
        if (!$this->TBPERFIL->exists($id)) {
            throw new NotFoundException(__('Invalid t b p e r f i l'));
        }
        if ($this->request->is('post') || $this->request->is('put')) {
            if ($this->TBPERFIL->save($this->request->data)) {
                $this->Session->setFlash(__('The t b p e r f i l has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The t b p e r f i l could not be saved. Please, try again.'));
            }
        } else {
            $options = array('conditions' => array('TBPERFIL.' . $this->TBPERFIL->primaryKey => $id));
            $this->request->data = $this->TBPERFIL->find('first', $options);
        }
    }

    /**
     * delete method
     *
     * @throws NotFoundException
     * @throws MethodNotAllowedException
     * @param string $id
     * @return void
     */
    public function delete($id = null) {
        $this->TBPERFIL->id = $id;
        if (!$this->TBPERFIL->exists()) {
            throw new NotFoundException(__('Invalid t b p e r f i l'));
        }
        $this->request->onlyAllow('post', 'delete');
        if ($this->TBPERFIL->delete()) {
            $this->Session->setFlash(__('T b p e r f i l deleted'));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('T b p e r f i l was not deleted'));
        $this->redirect(array('action' => 'index'));
    }

    /**
     * n_index method
     *
     * @return void
     */
    public function n_index() {
        $this->TBPERFIL->recursive = 0;
        $this->set('tBPERFILs', $this->paginate());
    }

    /**
     * n_view method
     *
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function n_view($id = null) {
        if (!$this->TBPERFIL->exists($id)) {
            throw new NotFoundException(__('Invalid t b p e r f i l'));
        }
        $options = array('conditions' => array('TBPERFIL.' . $this->TBPERFIL->primaryKey => $id));
        $this->set('tBPERFIL', $this->TBPERFIL->find('first', $options));
    }

    /**
     * n_add method
     *
     * @return void
     */
    public function n_add() {
        if ($this->request->is('post')) {
            $this->TBPERFIL->create();
            if ($this->TBPERFIL->save($this->request->data)) {
                $this->Session->setFlash(__('The t b p e r f i l has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The t b p e r f i l could not be saved. Please, try again.'));
            }
        }
    }

    /**
     * n_edit method
     *
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function n_edit($id = null) {
        if (!$this->TBPERFIL->exists($id)) {
            throw new NotFoundException(__('Invalid t b p e r f i l'));
        }
        if ($this->request->is('post') || $this->request->is('put')) {
            if ($this->TBPERFIL->save($this->request->data)) {
                $this->Session->setFlash(__('The t b p e r f i l has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The t b p e r f i l could not be saved. Please, try again.'));
            }
        } else {
            $options = array('conditions' => array('TBPERFIL.' . $this->TBPERFIL->primaryKey => $id));
            $this->request->data = $this->TBPERFIL->find('first', $options);
        }
    }

    /**
     * n_delete method
     *
     * @throws NotFoundException
     * @throws MethodNotAllowedException
     * @param string $id
     * @return void
     */
    public function n_delete($id = null) {
        $this->TBPERFIL->id = $id;
        if (!$this->TBPERFIL->exists()) {
            throw new NotFoundException(__('Invalid t b p e r f i l'));
        }
        $this->request->onlyAllow('post', 'delete');
        if ($this->TBPERFIL->delete()) {
            $this->Session->setFlash(__('T b p e r f i l deleted'));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('T b p e r f i l was not deleted'));
        $this->redirect(array('action' => 'index'));
    }

    public function validarCadastro() {
        if (!empty($this->request->data)) {
            return $this->erros();
        }
    }
}    